define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'qrcode', 'layer', 'upload'], function ($, undefined, Backend, Table, Form, qrcode, layer, Upload) {
 
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    ajaxOperate : ['add','edit']
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                pk: 'id',
                sortName: 'id',
                queryParams:function(params) {
                    // 要显示的字段
                    // params.fields = '';
                    // // 要关联的拓展信息
                    // params.extra = 'partner,open_auth';
                    // return params;
                },
                // search:true,
                // commonSearch: true,
                // searchFormVisible: false,
                columns: [
                    [
                        // {field: 'state', checkbox: true, },
                        {field: 'id', title: 'ID',operate:false},
                        {field: 'name', title: '产品名称',align:'left'},
                        {field: 'customer_point', title: '客户经理所得积分',operate: false},
                        {field: 'distributor_point', title: '分销商所得积分',operate: false},
                        {field: 'status', title: '状态', formatter: function (value, row, index) {
                            return (row.status == 1) ? '正常' : '下架';
                            },operate:false},
                        {field: 'create_time', title: '创建时间', formatter: Table.api.formatter.datetime,operate:false},
                        {field: 'update_time', title: '最后修改时间', formatter: Table.api.formatter.datetime,operate:false},
                        {field: 'operate', title: __('Operate'), events: Controller.api.events.operate, formatter: Controller.api.formatter.operate},
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter:{
                operate: function (value, row, index) {
                    return Table.api.formatter.operate(value, row, index, $("#table"));
                }
            },
            events:{
                operate: $.extend({

                }, Table.api.events.operate)
            }
        }
    }
    return Controller;
});